package com.jiot.controller.user;

import com.zg.cloud.BaseResponse;
import com.zg.cloud.annotation.RoleCheck;
import com.zg.cloud.annotation.TokenCheck;
import com.zg.cloud.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import req.role.AddRoleReq;
import com.zg.cloud.CommonEnum.Role;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author liling
 * @date 2020/10/12 10:01
 * @description
 **/
@RestController
@RequestMapping("/user/role")
@Api(value = "角色模块")
public class RoleController {

    @Resource
    private RoleService roleService;

    @RoleCheck({Role.SYS_ADMIN, Role.ADMIN, Role.PROVINCE_ADMIN, Role.CITY_ADMIN, Role.DISTRICT_ADMIN})
    @PostMapping("/add")
    @TokenCheck
    @ApiOperation(value = "新增角色", notes = "role")
    public BaseResponse add(@RequestBody @Valid AddRoleReq addRoleReq) {
        if (roleService.addRole(addRoleReq)) {
            return new BaseResponse();
        }
        return new BaseResponse();
    }

    @RoleCheck({Role.SYS_ADMIN, Role.ADMIN, Role.PROVINCE_ADMIN, Role.CITY_ADMIN, Role.DISTRICT_ADMIN})
    @PostMapping("/drop/down/list")
    @TokenCheck
    @ApiOperation(value = "角色下拉列表", notes = "role")
    public BaseResponse dropDownList() {
        return new BaseResponse(roleService.dropDownList());
    }
}
